<?php

namespace model;

include_once APP_PATH . './model/Model.php';

class Log extends Model
{
    public function write($log)
    {
        $baseLog = [
            'time' => date("Y-m-d H:i:s", time()),
            'ip' => $_SERVER['REMOTE_ADDR']
        ];
        $log = array_merge($log, $baseLog);

        $file = fopen("./logs/" . date("Y-m-d") . ".txt", 'a+');
        if ($file) {
            fwrite($file, json_encode($log, JSON_UNESCAPED_UNICODE) . PHP_EOL);
            fclose($file);
        } else {
            echo "打开文件错误";
            exit();
        }
    }
}